package com.wunu.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.wunu.annotation.CurrentUser;
import com.wunu.config.ResponseHelper;
import com.wunu.config.ResponseModel;
import com.wunu.entity.Lock;
import com.wunu.entity.User;
import com.wunu.service.ICmdIssuedMongodbService;
import com.wunu.service.IFacesLogMgdbService;
import com.wunu.service.IImageMgDbService;
import com.wunu.service.ILockService;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * *门锁信息 前端控制器
 * </p>
 *
 * @author wunu kin
 * @since 2019-04-11
 */
@CrossOrigin
@RestController
@RequestMapping("/lock")
public class LockController {

    @Autowired
    private ILockService lockService;
    @Autowired
    private IFacesLogMgdbService facesLogMgdbService;
    @Autowired
    private IImageMgDbService imageMgDbService;
    @Autowired
    private ICmdIssuedMongodbService cmdIssuedMongodbService;  
    /**
     * *获取门锁信息列表
     * @param pageIndex
     * @param pageSize
     * @return
     * @throws Exception
     */
    @GetMapping("/lockList")
    public ResponseModel<Page<Lock>> findLockList(@CurrentUser User user, @RequestParam(name = "pageIndex", defaultValue = "1", required = false) Integer pageIndex,
                                      @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize,
                                      @RequestParam(value = "lockName",required = false) String lockName) throws Exception{
        return ResponseHelper.buildResponseModel(lockService.selectLocksByUserNoPage(new Page<Lock>(pageIndex, pageSize),lockName,user.getUserNo()));
    }


    /**
     ** 下发人脸数据信息
     * @param requestJson
     * @return
     * @throws Exception
     */
    @GetMapping("/imageList")
    public ResponseModel<Map<String, Object>> findImageList(@CurrentUser User user, @RequestParam(name = "pageIndex", defaultValue = "1", required = false) Integer pageIndex,
                                      @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize,
        @RequestParam(value = "clientId", required = true) String clientId) throws Exception{
    	return ResponseHelper.buildResponseModel(imageMgDbService.getSendImageData(pageIndex, pageSize,clientId));
    }
    
    /**
     ** 下发卡号数据信息
     * @param requestJson
     * @return
     * @throws Exception
     */
    @GetMapping("/cmdList")
    public ResponseModel<Map<String, Object>> findCardNoList(@CurrentUser User user, @RequestParam(name = "pageIndex", defaultValue = "1", required = false) Integer pageIndex,
                                      @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize,
                                      @RequestParam(value = "clientId", required = true) String clientId) throws Exception{
    	return ResponseHelper.buildResponseModel(cmdIssuedMongodbService.getSendCmd(pageIndex, pageSize,clientId));
    }
    
    /**
     ** 开门日志
     * @return
     * @throws Exception
     */
    @GetMapping("/logList")
    public ResponseModel<Map<String, Object>> getLogListt(@CurrentUser User user, @RequestParam(name = "pageIndex", defaultValue = "1", required = false) Integer pageIndex,
            @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize,
            @RequestParam(name = "startTime", defaultValue = "", required = false) String startTime,
            @RequestParam(name = "endTime", defaultValue = "", required = false) String endTime,
            @RequestParam(value = "lockId",required = true) Integer lockId) throws Exception{
    	return ResponseHelper.buildResponseModel(facesLogMgdbService.getLogPage(pageIndex, pageSize,lockId,startTime,endTime));
	}
}

